package cn.ac.iscas.service.junit;


import java.util.Calendar;
import java.util.LinkedHashMap;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;


import cn.ac.iscas.bean.QueryResult;
import cn.ac.iscas.bean.project.Project;
import cn.ac.iscas.bean.project.State;
import cn.ac.iscas.service.project.IProjectService;

public class ProjectJunitTestTest {
	private static IProjectService service;
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		try {
			ApplicationContext act = new ClassPathXmlApplicationContext("application-context.xml");
			service= (IProjectService)act.getBean("projectServiceImp");
		} catch (RuntimeException e) {
			e.printStackTrace();
		}	
	}
	@Test
	public void save()
	{
		Project project = new Project();
		Calendar c1 = Calendar.getInstance();
		c1.set(2010, 11, 2);
		project.setEndTime(c1);
		project.setIntroduction("好项目");
		project.setNote("ddd");
		project.setPatentTarget(3);
		project.setState(State.申请中);
		c1.set(2010, 11, 5);
		project.setStartTime(c1);
		project.setSource("国家自然科学基金");
		project.setSoftwareCopyRightTarget(4);
		project.setReposiblePerson("温家宝");
		project.setProjectName("李刚儿子");
		project.setProjectNo("NO.12342322325");
		project.setPaperTarget(6);
		project.setPersonInCharge("张晓杰");
		for(int i=0;i<30;i++)
		{
			service.save(project);
		}
	}
	@Test
	public void find()
	{
		LinkedHashMap<String,String> orderby = new LinkedHashMap<String,String>();
		orderby.put("id", "desc");
		QueryResult<Project> projects = service.getScrollData(Project.class, 0, 4, "o.projectName=?", new Object[]{"核电站"}, orderby);
		for(Project p:projects.getResultlist())
		{
			System.out.println(p.getId());
		}
		
	}
}
